//数字每三位添加逗号
import { addCommas } from '@/utils/util.js'
//字体颜色
const fontColor = 'rgba(0,0,0,0.65)';
//宽度比值
const aspectRatio = (window.innerWidth > 1200) ? (window.innerWidth / 1920) : 1;
//防止标签溢出
const optionGird = {
  // containLabel: true
}
//柱体上显示数值
const seriesLabel = {
  show: false,//开启显示
  // position: 'top',//在上方显示
  // rotate: 45,
  // textStyle: {//数值样式
  //   fontSize: '12px',
  //   color: '#000',
  // },
  // formatter: (params) => {
  //   return addCommas(params?.value)
  // },
}
// 提示框背景
const optionTooltip = {
  backgroundColor: 'rgba(0,0,0,0.65)',  // 提示框背景色
  borderWidth: '0',
  padding: [5, 10],                     // 内边距
  textStyle: {                           // 文本样式
    color: '#fff',                     // 文本颜色
    fontSize: 12                       // 文本字号
  },
}
//图表定位
const gridPosition = {
  left: '60px',
  top: '30px',
  right: '30px',
  bottom: '50px'
}
//带legend，图表定位
const gridLengedPosition = {
  position: {
    left: '60px',
    top: '60px',
    right: '30px',
    bottom: '50px'
  },
  legendTop : '20px'
}
//横坐标字体颜色
const xAxisAxisLabel = {
  color: 'rgba(0,0,0,0.65)'
}
//纵坐标字体颜色及展示
const yAxisAxisLabel = {
  color: 'rgba(0,0,0,0.65)',
  formatter: function(params){
    if(!params) return 0;
    if(params >= 100000000 || params <= -100000000){
      return `${addCommas(Math.ceil(params / 100000000))}亿`;
    }else if(params >= 10000 || params <= -10000){
      return `${addCommas(Math.ceil(params / 10000))}万`;
    }else{
      return params;
    }
  }
}
//纵坐标字体颜色及展示
const yAxisAxisLabelPercent = {
  color: 'rgba(0,0,0,0.65)',
  formatter: function(params){
    if(!params) return 0;
    return `${addCommas(params)}%`;
  }
}
//横坐标轴颜色及宽度
const xAxisAxisLine = {
  lineStyle: {
    color: 'rgb(215, 215, 215)', // 设置横坐标轴线的颜色
    width: 1.5
  }
}
//图表线
const yAxisSplitLine = {
  show:true,
  lineStyle:{
    type:'dashed',
    color: '#e9e9e9',
    width: 0.8, // 线宽
    dashOffset: 10 // 设置虚线的偏移
  }
}
//改变单位
const changeUnit = (number) => {
  if(!number) return 0;
  if(number >= 100000000 || number <= -100000000){
    return `${(number / 100000000).toFixed(2)} 亿元`;
  }else if(number >= 10000 || number <= -10000){
    return `${(number / 10000).toFixed(2)} 万元`;
  }else{
    return `${number} 元`;
  }
}
//计算最大值
const calMax = (arr) => {
  if(!arr?.length) return 1;
  let maxOrg = Math.max(...arr);
  let max = Math.abs(Math.ceil(maxOrg));
  let len = max.toString().length-1;
  let pow = Math.pow(10, len);
  let maxint = Math.ceil(max / pow);
  let maxval = maxOrg < 0 ? -maxint * pow : maxint * pow;
  if(maxval < 0){ maxval = 0 }
  return maxval;

}
//计算最小值
const calMin = (arr) => {
  if(!arr?.length) return 1;
  let minOrg = Math.min(...arr);
  let min = Math.abs(Math.ceil(minOrg));
  let len = min.toString().length-1;
  let pow = Math.pow(10, len);
  let minint = Math.ceil(min / pow);
  let minval = minOrg < 0 ? -minint * pow : minint * pow;
  if(minval > 0){ minval = 0 }
  return minval;
}
//月利润趋势
export const lineOptions = (options) => {
  return {
    grid: {...gridPosition, ...optionGird},
    xAxis: {
      type: 'category',
      data: options?.dataList?.map(item => item?.dateStr) || [],
      axisLabel: xAxisAxisLabel,
      axisLine: xAxisAxisLine
    },
    yAxis: {
      type: 'value',
      axisLabel: yAxisAxisLabel,
      splitLine: yAxisSplitLine,
      axisLine: xAxisAxisLine
    },
    series: [
      {
        data: options?.dataList?.map(item => item?.itemValue) || [],
        type: 'line',
        lineStyle: {
          color: '#1890FF'
        },
        itemStyle: {
          color: '#1890FF'
        }
      }
    ],
    tooltip: {...{
      show: true,                  // 是否显示提示框，默认为 true
      trigger: 'axis',             // 触发类型，可选值: 'item'（数据项触发），'axis'（坐标轴触发），'none'（不触发）
      axisPointer: {
        type: 'none'
      },
      formatter: function(params) {
        if(!params?.length) return '';
        var result = '';
        params.forEach(function (item) {
          if(!item) return '';
          result+=item.marker + " " + (item.name || '') + " : " + addCommas(changeUnit(item.value || 0)) +"</br>";
        });
        return result;
      }
    }, ...optionTooltip},
  }
}

//利润表展示
export const barOptions = (options) => {
  return {
    grid: {...gridPosition, ...optionGird},
    xAxis: {
      type: 'category',
      data: options?.dataList?.map(item => item?.item) || [],
      axisLine: xAxisAxisLine,
      axisLabel: {...{
        interval: 0,
        fontSize: (aspectRatio == 1) ? 12 : ( 12 * aspectRatio * 0.85),
        // lineHeight: 15,
        // formatter:function(params){
        //   if(!params) return '';
        //   let list = params.split('') || [];
        //   let result = '';
        //   list?.forEach((item, index) => {
        //     result+=item;
        //     if(list.length > 2 && !((index + 1) % 2)){
        //       result+='\n'
        //     }
        //   })
        //   return result;
        // }
      }, ...xAxisAxisLabel}
    },
    yAxis: {
      type: 'value',
      axisLabel: yAxisAxisLabel,
      splitLine: yAxisSplitLine,
      axisLine: xAxisAxisLine
    },
    series: [
      {
        data: options?.dataList?.map(item => item?.itemValue) || [],
        type: 'bar',
        barWidth: '35%',
        itemStyle: {
          normal: {
            color: function(params){
              if(!params) return '';
              let colorList = [
                '#58dfd8',
                '#fed454',
                '#fd8d9a',
                '#f5b482',
                '#70b603',
                '#69c0ff'
              ]
              return colorList?.[params?.dataIndex];
            }
          }
        },
        label: seriesLabel
      }
    ],
    tooltip: {...{
      show: true,                  // 是否显示提示框，默认为 true
      trigger: 'axis',             // 触发类型，可选值: 'item'（数据项触发），'axis'（坐标轴触发），'none'（不触发）
      axisPointer: {
        type: 'shadow'
      },
      formatter: function(params) {
        if(!params?.length) return '';
        var result = '';
        params.forEach(function (item) {
          if(!item) return '';
          result+=item.marker + " " + (item.name || '') + " : " + addCommas(changeUnit(item.value || 0)) +"</br>";
        });
        return result;
      }
    }, ...optionTooltip},
  }
};

//营运能力展示
export const radarOptions = (options) => {
  //去除没有数据的值，不然图表无法正常展示
  options.dataList = options?.dataList?.filter(item => item?.dataList?.length) || [];
  let indicator =  options?.dataList?.[0]?.dataList?.map(item => {
    return {
      name: item?.item
    }
  }) || [];
  return {
    grid: {...{
    }, ...optionGird},
    legend: {
      top: gridLengedPosition.legendTop,
      // align: 'right',
      textStyle: {
        color: fontColor
      },
      data: options?.dataList?.map(item => item?.name) || [],
    },
    radar: {
      radius: '55%',
      indicator: indicator,
      nameGap: 5,
      name: {
        textStyle: {
          color: fontColor,
        },
        fontSize: 12 * aspectRatio,
        // lineHeight: 15,
        // formatter:function(params){
        //   if(!params) return '';
        //   let list = params.split('') || [];
        //   let result = ''
        //   list?.forEach((item, index) => {
        //     result+=item;
        //     if(list.length > 4 && !((index + 1) % 4)){
        //       result+='\n'
        //     }
        //   })
        //   return result;
        // }
      },
    },
    series: [
      {
        name: 'Budget vs spending',
        type: 'radar',
        data: indicator?.length ? options?.dataList?.map(item => {
          return {
            value: item?.dataList?.map(childItem => childItem?.itemValue) || [],
            name: item?.name,
            itemStyle: {              // 设置每个数据项的样式
              color: item?.name === '公司总体' ? '#25bc74' : '#1890ff'     // 设置为黄色
            }
          }
        }) : []
      }
    ],
    tooltip: {...{
      show: true,                  // 是否显示提示框，默认为 true
      // trigger: 'axis',             // 触发类型，可选值: 'item'（数据项触发），'axis'（坐标轴触发），'none'（不触发）
      axisPointer: {
        type: 'none',
      },
      formatter: function(params){
        if(!params) return '';
        var result = `<div style="height: 24px;">${params.name || ''}</div>`
        params.value?.forEach(function (item, index) {
          let itemResult = !item ? 0 : `${addCommas(item)}%`
          result+=`<div style="height: 24px;">${params.marker}<span>${indicator?.[index]?.name || ''}</span><span style="float: right;margin-left: 20px">${itemResult}</span></div>`
        });
        return result;
      }
    }, ...optionTooltip},
  }
};

//盈利能力展示
export const stackedOptions = (options, dateType) => {
  let curText = dateType === '0' ? '月' : (dateType === '1' ? '季度' : '年');
  return {
    grid: {...gridLengedPosition.position, ...optionGird},
    tooltip: {...{
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      },
      formatter: function(params){
        if(!params?.length) return '';
        let result = `<div style="height: 24px;">${params[0]?.name || ''}</div>`
        params.forEach(function(item, index) {
          if(!item) return '';
          result+=`<div style="height: 24px;">${item.marker}<span>${item.seriesName || ''}</span><span style="float: right;margin-left: 20px">${addCommas(changeUnit(item.value || 0))}</span></div>`
        })
        return result;
      }
    }, ...optionTooltip},
    color: ['#3ba1ff', '#58dfd8', '#d8efff'],
    legend: {
      data: [`上${curText}比值`, `本${curText}比值`, '增减值'],
      // align: 'right',
      top: gridLengedPosition.legendTop,
      textStyle: {
        color: fontColor
      }
    },
    xAxis: [
      {
        type: 'category',
        axisTick: { show: false },
        data: options?.dataList?.map(item => item?.name) || [],
        axisLine: xAxisAxisLine,
        axisLabel: {...{
          interval: 0,
          fontSize: (aspectRatio == 1) ? 12 : ( 12 * aspectRatio * 0.85),
          // lineHeight: 15, 
          // formatter:function(params){
          //   if(!params) return '';
          //   let list = params.split('') || [];
          //   let result = '';
          //   list?.forEach((item, index) => {
          //     result+=item;
          //     if(list.length > 6 && !((index + 1) % 6)){
          //       result+='\n'
          //     }
          //   })
          //   return result;
          // }
        }, ...xAxisAxisLabel}
      }
    ],
    yAxis: [
      {
        type: 'value',
        axisLabel: yAxisAxisLabel,
        splitLine: yAxisSplitLine,
        axisLine: xAxisAxisLine
      }
    ],
    series: [
      {
        name: `上${curText}比值`,
        type: 'bar',
        barGap: 1,
        label: seriesLabel,
        emphasis: {
          focus: 'series'
        },
        data: options?.dataList?.map(item => item?.lastValue) || []
      },
      {
        name: `本${curText}比值`,
        type: 'bar',
        barGap: 1,
        label: seriesLabel,
        emphasis: {
          focus: 'series'
        },
        data: options?.dataList?.map(item => item?.curValue) || []
      },
      {
        name: '增减值',
        type: 'bar',
        barGap: 1,
        label: seriesLabel,
        emphasis: {
          focus: 'series'
        },
        data: options?.dataList?.map(item => item?.diffValue) || []
      },
    ],
  }
};

//现金净流量增长情况
export const WaterfallOptions = (options) => {
  /**
   * 情形一，变化前后值符号相反，贯穿X轴
   * 情形二，变化前后有一个值为0
   * 情形三，变化前后，值都为正，增减值为正或负
   * 情形四，变化前后，值都为负，增减值为正或负
   */
  let result = [], result1 = [], result2 = [];
  options?.dataList?.reduce((prev, cur, index) => {
    let curSum = (prev * 100 + (cur.itemValue * 100 || 0)) / 100;
    if((prev > 0 && curSum < 0) || (prev < 0 && curSum > 0)){
      //情形一
      result.push(0);
      result1.push(prev);
      result2.push(curSum);
    }else{
      if(prev > 0 && curSum > 0){
        //情形三
        result.push(Math.min(prev, curSum));
        result1.push(Math.abs(cur.itemValue || 0));
      }else if(prev < 0 && curSum < 0){
        //情形四
        result.push(Math.max(prev, curSum));
        result1.push(0 - Math.abs(cur.itemValue || 0));
      }else if(prev === 0 || curSum === 0){
        //情形二
        result.push(0);
        result1.push(prev === 0 ? curSum : prev);
      }
      result2.push('-');
    }
    return curSum;
  }, 0)
  return {
    grid: {...gridPosition, ...optionGird},
    tooltip: {...{
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      },
      formatter: function(params) {
        if(!params?.length) return '';
        let result = options?.dataList?.map(item => item.itemValue) || [];
        return params[1]?.marker + " " + (params[1]?.name || '') + " : " + addCommas(changeUnit(result[params[1]?.dataIndex] || 0));
      }
    }, ...optionTooltip},
    xAxis: {
      type: 'category',
      splitLine: { show: false },
      axisLabel: xAxisAxisLabel,
      axisLine: xAxisAxisLine,
      data: options?.dataList?.map(item => item?.dateStr) || []
    },
    yAxis: {
      type: 'value',
      axisLabel: yAxisAxisLabel,
      splitLine: yAxisSplitLine,
      axisLine: xAxisAxisLine
    },
    series: [
      {
        name: 'Placeholder',
        type: 'bar',
        stack: 'Total',
        barWidth: '35%',
        itemStyle: {
          borderColor: 'transparent',
          color: 'transparent'
        },
        emphasis: {
          itemStyle: {
            borderColor: 'transparent',
            color: 'transparent'
          }
        },
        data: result || []
      },
      {
        name: 'Life Cost',
        type: 'bar',
        stack: 'Total',
        label: {
          show: true,
          position: 'inside'
        },
        data: result1?.map((item, index) => {
          return {
            value: item || 0,
            label: {
              show: false,
              // position: 'top',
              // rotate: 45,
              // formatter: () => {
              //   return addCommas(item)
              // },
            },
            itemStyle: {color: options?.dataList?.[index]?.itemValue > 0 ? '#3ba1ff' : '#fed454'},
          }
        }) || []
      },
      {
        name: 'Life Cost',
        type: 'bar',
        stack: 'Total',
        label: {
          show: true,
          position: 'inside'
        },
        data: result2?.map((item, index) => {
          return {
            value: item || 0,
            label: {
              show: false,
              // position: 'top',
              // rotate: 45,
              // formatter: () => {
              //   return addCommas(item)
              // },
            },
            itemStyle: {color: options?.dataList?.[index]?.itemValue > 0 ? '#3ba1ff' : '#fed454'},
          }
        }) || []
      }
    ]
  }
};

//资金收支情况
export const stackedHorizontalOptions = (options) => {
  return {
    grid: {...gridLengedPosition.position, ...optionGird},
    tooltip: {...{
      trigger: 'axis',
      axisPointer: {
        // Use axis to trigger tooltip
        type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
      },
      formatter: function(params){
        if(!params?.length) return '';
        let result = `<div style="height: 24px;">${params[0]?.name || ''}</div>`
        params.forEach(function(item, index) {
          if(!item) return '';
          result+=`<div style="height: 24px;">${item.marker}<span>${item.seriesName || ''}</span><span style="float: right;margin-left: 20px">${addCommas(changeUnit(item.value || 0))}</span></div>`
        })
        return result;
      }
    }, ...optionTooltip},
    color: ['#1890ff', '#58dfd8', '#d8efff', '#fed454'],
    legend: {
      top: gridLengedPosition.legendTop,
      // align: 'right',
      textStyle: {
        color: fontColor,
      }
    },
    xAxis: {
      type: 'value',
      splitLine: yAxisSplitLine,
      axisLabel: yAxisAxisLabel,
      axisLine: xAxisAxisLine
    },
    yAxis: {
      type: 'category',
      axisLabel: xAxisAxisLabel,
      axisLine: xAxisAxisLine,
      data: options?.dataList?.map(item => item?.name) || []
    },
    series: options?.dataList?.[0]?.dataList ? Object.keys(options.dataList[0].dataList)?.map(item => {
      return {
        name: item,
        type: 'bar',
        stack: 'total',
        barWidth: '35%',
        emphasis: {
          focus: 'series'
        },
        data: options?.dataList?.map(childItem => childItem?.dataList?.[item]) || []
      }
    }) : []
  }
};

//回款情况展示
export const liquidFillOptions = (options, color, title) => {
  return {
    title: {
      text: title,
      left: 'center',
      bottom: '16%',
      textStyle: {
        color: fontColor,
        fontSize: 12
      }
    },
    grid: {...{
    }, ...optionGird},
    // 提示框组件
    tooltip: {...{
      trigger: "item", // 触发类型, 数据项图形触发，主要在散点图，饼图等无类目轴的图表中使用。
      // 提示框浮层内容格式器，支持字符串模板和回调函数两种形式
      // 水球图: {a}（系列名称），{b}（无），{c}（数值）
      // 使用函数模板   传入的数据值 -> value: number|Array,
      formatter: function (params) {
        if(!params || !options) return '';
        let value = !options.itemValue ? 0 : `${addCommas(options.itemValue)}%`;
        return params.marker + (params.seriesName || '') + " : " + value;
      }
    }, ...optionTooltip},
    series: [
      {
        type: "liquidFill", // 图表类型
        name: options.item,
        radius: "70%",
        center: ["50%", "38%"],
        data: [ (options?.itemValue / 100) || 0 ], // data个数代表波浪数
        backgroundStyle: {
          borderWidth: 1,
          color: "#fff"
        },
        //去掉波浪阴影
        itemStyle: {
          opacity: 0.95,
          shadowColor: 'rgba(0, 0, 0, 0)',
        },
        color: [  //color一定要是个数组 ，每一项对应一个波浪，可以给每个波浪单独配置颜色
          {
            type: "linear",
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 1,
                color: color
              },
              {
                offset: 0,
                color: "rgba(103,205,251,1)"
              }
            ],
            globalCoord: false
          }
        ],
        outline: {
          show: false
        },
        label: {
          normal: {
            fontSize: 12,
            color: fontColor,
            insideColor: fontColor,
            formatter: function (params) {
              if(!options) return '';
              return !options.itemValue ? 0 : `${addCommas(options.itemValue)}%`;
            }
          }
        }
      },
      //外层线
      {
        type: "pie",
        center: ["50%", "38%"],
        radius: ["75%", "80%"], //外层线粗细
        hoverAnimation: false,
        data: [
          {
            name: "",
            value: 100,
            labelLine: {
              show: false
            },
            itemStyle: {
              color: color
            },
            emphasis: {
              labelLine: {
                show: false
              },
            }
          }
        ],
        tooltip: {
          show: false
        }
      },
    ]
  }  
};

//营运能力分析
export const halfDoughnutOptions = (options, color) => {
  return {
    grid: {...{
    }, ...optionGird},
    graphic: {
      type: "text",
      left: "center",
      top: "68%",
      style: {
        //数据总量
        text: options?.dateStr || '',
        textAlign: "center",
        fill: fontColor,
        fontSize: 12
      }
    },
    tooltip: {...{
      trigger: 'item',
      formatter: function(params) {
        if(!params) return '';
        return params.marker + " " + (params.name || '') + " : " + addCommas(params.value || 0);
      }
    }, ...optionTooltip},
    //数值均为0不展示
    series: (options?.dataList && Object.values(options.dataList))?.some(item => item) ?
      [
        {
          name: options?.dateStr || '',
          type: 'pie',
          radius: ['60%', '85%'],
          center: ['50%', '60%'],
          // adjust the start and end angle
          startAngle: 180,
          endAngle: 360,
          label: {
            show: true,
            position: 'inside',
            textStyle: {
              color: fontColor
            }
          },
          data: options?.dataList ? Object.keys(options.dataList)?.map((item, index) => {
            return {
              value: (options?.dataList && Object.values(options.dataList))?.[index],
              name: item
            }
          }) : [],
          itemStyle: {
            normal: {
              color: function(params){
                return color?.[params?.dataIndex]
              }
            }
          }
        }
      ] : []
  }
};

//平台回款情况
export const basicAreaOptions = (options) => {
  //去除店铺收入中的回款率
  options?.dataList?.forEach(item => {
    if(item.name === '回款率'){
      if(item.dataList){
        item.dataList['店铺收入'] = '';
      }
    }
  })
  let hklList = [];
  let hklOtherList = [];
  options?.dataList?.forEach(item => {
    if(item.name === '回款率'){
      hklList = item.dataList ? Object.values(item.dataList) : []
    }else{
      hklOtherList = item.dataList ? Object.values(item.dataList) : []
    }
  })
  return {
    grid: {...gridLengedPosition.position, ...optionGird, right: '60px'},
    tooltip: {...{
      trigger: 'axis',
      axisPointer: {
        type: 'none',
      },
      formatter: function(params){
        if(!params?.length) return '';
        let result = `<div style="height: 24px;">${params[0]?.name || ''}</div>`
        params.forEach(function(item, index) {
          if(!item) return '';
          if(params[0]?.name === '店铺收入' && item.seriesName === '回款率') return;
          let value;
          if(item.seriesName === '回款率'){
            value = !item.value ? 0 : `${addCommas(item.value)}%`;
          }else{
            value = !item.value ? 0 : addCommas(changeUnit(item.value));
          }
          result+=`<div style="height: 24px;">${item.marker}<span>${item.seriesName || ''}</span><span style="float: right;margin-left: 20px">${value}</span></div>`
        })
        return result;
      }
    }, ...optionTooltip},
    legend: {
      data: options?.dataList?.map(item => item?.name) || [],
      // align: 'right',
      top: gridLengedPosition.legendTop,
      textStyle: {
        color: fontColor
      }
    },
    xAxis: [
      {
        type: 'category',
        boundaryGap: false,
        axisLabel: xAxisAxisLabel,
        axisLine: xAxisAxisLine,
        data: options?.dataList?.[0]?.dataList ? Object.keys(options.dataList[0].dataList) : []
      }
    ],
    yAxis: [
      {
        type: 'value',
        axisLabel: yAxisAxisLabel,
        splitLine: yAxisSplitLine,
        axisLine: xAxisAxisLine,
        min: calMin(hklOtherList),
        max: calMax(hklOtherList),
        splitNumber: 5,
        interval: (calMax(hklOtherList) - calMin(hklOtherList)) / 5
      },
      {
        type: 'value',
        axisLabel: yAxisAxisLabelPercent,
        splitLine: yAxisSplitLine,
        axisLine: xAxisAxisLine,
        min: calMin(hklList),
        max: calMax(hklList),
        splitNumber: 5,
        interval: (calMax(hklList) - calMin(hklList)) / 5
      }
    ],
    series: options?.dataList?.map(item => {
      return {
        name: item?.name,
        type: 'line',
        stack: `Total-${item?.name}`,
        areaStyle: {
          opacity: item?.name === '金额' ? 1 : 0
        },
        emphasis: {
          focus: 'series'
        },
        data: (item?.dataList && Object.values(item.dataList)) || [],
        itemStyle: {
          color: item?.name === '金额' ? '#f7ae4e' : '#1890ff' // 设置背景颜色为黄色
        },
        yAxisIndex: item?.name === '金额' ? 0 : 1
      }
    }) || []
  }
};

//月净利润趋势
export const stackedAreOptions = (options) => {
  let colorList = ['#95D3F7', '#50A5FE', '#3678FA', '#D8EFFF'];
  let jlrlList = [];
  let jlrlOtherList = [];
  options?.dataList?.forEach(item => {
    if(!item?.dataList) return;
    jlrlList.push(item.dataList['净利润率'])
    jlrlOtherList.push(item.dataList['净利润'])
    jlrlOtherList.push(item.dataList['营业成本'])
    jlrlOtherList.push(item.dataList['营业收入'])
  })
  return {
    grid: {...gridPosition.position, ...optionGird, right: '50px', bottom: '50px', left: '70px'},
    tooltip: {...{
      trigger: 'axis',
      axisPointer: {
        type: 'none'
      },
      formatter: function(params){
        if(!params?.length) return '';
        let result = `<div style="height: 24px;">${params[0]?.name || ''}</div>`
        params.forEach(function(item, index) {
          if(!item) return '';
          let value;
          if(item.seriesName.indexOf('率') > -1){
            value = !item.value ? 0 : `${addCommas(item.value)}%`;
          }else{
            value = !item.value ? 0 : addCommas(changeUnit(item.value));
          }
          result+=`<div style="height: 24px;">${item.marker}<span>${item.seriesName || ''}</span><span style="float: right;margin-left: 20px">${value}</span></div>`
        })
        return result;
      }
    }, ...optionTooltip},
    legend: {
      data: options?.dataList?.[0]?.dataList ? Object.keys(options.dataList[0].dataList) : [],
      // align: 'right',
      top: gridLengedPosition.legendTop,
      textStyle: {
        color: fontColor
      }
    },
    xAxis: [
      {
        type: 'category',
        boundaryGap: false,
        axisLabel: xAxisAxisLabel,
        axisLine: xAxisAxisLine,
        data: options?.dataList?.map(item => item?.dateStr) || []
      }
    ],
    yAxis: [
      {
        type: 'value',
        axisLabel: yAxisAxisLabel,
        splitLine: yAxisSplitLine,
        axisLine: xAxisAxisLine,
        min: calMin(jlrlOtherList),
        max: calMax(jlrlOtherList),
        splitNumber: 5,
        interval: (calMax(jlrlOtherList) - calMin(jlrlOtherList)) / 5
      },
      {
        type: 'value',
        axisLabel: yAxisAxisLabelPercent,
        splitLine: yAxisSplitLine,
        axisLine: xAxisAxisLine,
        min: calMin(jlrlList),
        max: calMax(jlrlList),
        splitNumber: 5,
        interval: (calMax(jlrlList) - calMin(jlrlList)) / 5
      }
    ],
    series: options?.dataList?.[0]?.dataList ? Object.keys(options.dataList[0].dataList).map((item, index) => {
      return {
        name: item,
        type: 'line',
        stack: `Total-${item}`,
        areaStyle: {
          opacity: item === '净利润率' ? 0 : 1
        },
        emphasis: {
          focus: 'series'
        },
        data: options?.dataList?.map(childItem => childItem?.dataList?.[item]) || [],
        itemStyle: {
          color: colorList?.[index] // 设置背景颜色为黄色
        },
        yAxisIndex: item === '净利润率' ? 1 : 0
      }
    }) : []
  }
};

//年度发展趋势
export const stackedLineOptions = (options) => {
  let yAxisList = ['净资产', '总资产', '销售收入'];
  let colorList = ['#ffe062', '#ffbb89', '#50a5fe'];
  return {
    grid: {...optionTooltip, ...optionGird, left: '70px', top: '30px', bottom: '50px', right: '40px'},
    tooltip: {...{
      trigger: 'axis',
      axisPointer: {
        type: 'none'
      },
      formatter: function(params){
        if(!params?.length) return '';
        let optionResult = options?.dataList?.filter(optionItem => optionItem.name === params[0].name) || [];
        var result = `<div style="height: 24px;">${params[0]?.name || ''}</div>`
        params.forEach(function (item, index) {
          let growthRate = optionResult?.[0]?.dataList?.[`${item.seriesName} 增长率`];
          growthRate = !growthRate ? 0 : (growthRate > 0 ? `+${addCommas(growthRate)}%` : `${addCommas(growthRate)}%`);
          result+=`<div style="height: 24px;">${item.marker}<span>${item.seriesName || ''}</span><span style="float: right;margin-left: 20px">${addCommas(changeUnit(item.value || 0))}(${growthRate})</span></div>`
        });
        return result;
      }
    }, ...optionTooltip},
    xAxis: {
      type: 'category',
      boundaryGap: false,
      axisLabel: xAxisAxisLabel,
      axisLine: xAxisAxisLine,
      data: options?.dataList?.map(item => item?.name) || []
    },
    yAxis: [
      {
        type: 'category',
        axisLabel: xAxisAxisLabel,
        axisLine: xAxisAxisLine,
        data: yAxisList,
      },
      {
        type: 'value',
        axisLabel: xAxisAxisLabel,
        axisLine: xAxisAxisLine,
        show: false
      }
    ],
    series: yAxisList?.map((item, index) => {
      return {
        name: item,
        type: 'line',
        stack: 'Total',
        data: options?.dataList?.map(childItem => childItem?.dataList?.[item]) || [],
        itemStyle: {
          color: colorList?.[index] // 设置背景颜色为黄色
        },
        label: {
          show: true,//开启显示
          position: 'top',//在上方显示
          textStyle: {//数值样式
            fontSize: 12,
            color: fontColor,
          },
          formatter: (params) => {
            if(!params) return '';
            let result = options?.dataList?.filter(item => item.name === params.name) || [];
            let growthRate = result?.[0]?.dataList?.[`${params.seriesName} 增长率`];
            growthRate = !growthRate ? 0 : (growthRate > 0 ? `+${addCommas(growthRate)}%` : `${addCommas(growthRate)}%`);
            return `(${growthRate})`;
          },
        },
        yAxisIndex: 1
      }
    })
  }
};